{% template "admin/header.html" %}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>系统设置</legend>
    </fieldset>
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">基础设置</li>
            <li>SEO管理</li>
            <li>邮件设置</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form layui-form-pane" lay-filter="form-system">
                    <div class="layui-form-item">
                        <label class="layui-form-label">网站名称</label>
                        <div class="layui-input-4">
                            <input type="text" name="store_name" lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">网站域名</label>
                        <div class="layui-input-4">
                            <input type="text" name="site_url" lay-verify="url" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">网站LOGO</label>
                        <input type="hidden" name="logo" id="logo">
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn layui-btn-primary" id="logoBtn"><i class="icon icon-upload3"></i>点击上传</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="cltLogo">
                                    <p id="demoText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备案号</label>
                        <div class="layui-input-3">
                            <input type="text" name="record_no" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">Copyright</label>
                        <div class="layui-input-3">
                            <input type="text" name="copyright" placeholder="Copyright" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">地址</label>
                        <div class="layui-input-3">
                            <input type="text" name="address" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">电话</label>
                        <div class="layui-input-3">
                            <input type="text" name="phone" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱</label>
                        <div class="layui-input-3">
                            <input type="text" name="email" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="sys">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane" lay-filter="form-system">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-4">
                            <input type="text" name="store_title" lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">关键字</label>
                        <div class="layui-input-block">
                            <textarea name="store_keyword" lay-verify="required" placeholder="" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-block">
                            <textarea name="store_desc" lay-verify="required" placeholder="" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="sys">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

            <div class="layui-tab-item">
                <form class="layui-form layui-form-pane" lay-filter="form-system">
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮件服务</label>
                        <div class="layui-input-4">
                            <input type="text" name="smtp_sver" lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">发件账户</label>
                        <div class="layui-input-4">
                            <input type="text" name="smtp_user" lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发件人</label>
                        <div class="layui-input-4">
                            <input type="text" name="smtp_name" lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮件密码</label>
                        <div class="layui-input-4">
                            <input type="password" name="smtp_pass" lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮件端口</label>
                        <div class="layui-input-4">
                            <input type="text" name="smtp_port" lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">接收邮箱</label>
                        <div class="layui-input-4">
                            <input type="text" id="testuser" placeholder="" class="layui-input">
                        </div>
                        <button type="button" class="layui-btn" id="sendmail" >发送</button>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">测试内容</label>
                        <div class="layui-input-block">
                            <textarea id="testcent" placeholder="" class="layui-textarea">测试发送内容</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="sys">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>

</div>
{% template "admin/footer.html" %}
<script>

    layui.use(['form', 'layer','upload','element'], function () {
        var form = layui.form,layer = layui.layer,upload = layui.upload,$ = layui.jquery,element = layui.element;

        $.post("/admin/config/query",function (res) {
            var seytem = {};

            $.each(res.Data,function (k,v) {
                seytem[v.Name] = v.Value;
            });

            form.val("form-system", seytem);
            if(seytem.logo){
                $('#cltLogo').attr('src',seytem.logo);
            }
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#logoBtn'
            ,url: '/upload/file'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#cltLogo').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //上传成功
                if(res.Code>0){
                    $('#logo').val(res.Data);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


        $('#sendmail').click(function () {
            let user = $('#testuser').val();
            let cent = $('#testcent').val();
            if(user.length<=0){
                layer.msg('请输入接收邮箱');
                return;
            }
            if(cent.length<=0){
                layer.msg('请输入接收内容');
                return;
            }
            loading =layer.load(0, {shade: [0.1,'#fff']});
            $.post("/admin/config/sendMail",{user:user,cent:cent},function(res){
                layer.close(loading);
                if(res['Code']==1){
                    layer.msg('发送成功！',{icon: 1, time: 1000});
                }else{
                    layer.msg('发送失败！',{icon: 2, time: 1000});
                }
            });
        });

        //提交监听
        form.on('submit(sys)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            $.post("/admin/config/update",data.field,function(res){
                layer.close(loading);
                if(res.Code > 0){
                    layer.msg(res.Msg,{icon: 1, time: 1000},function(){
                        location.reload();
                    });
                }else{
                    layer.msg(res.Msg,{icon: 2, time: 1000});
                }
            });
        })
    })
</script>
</body>
</html>
